<!DOCTYPE html>
<title>Testing evaluation order</title>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
    setup({allow_uncaught_exception: true});

    window.log = [];

    window.addEventListener("error", ev => testDone());
    window.addEventListener("onunhandledrejection", unreachable);

    const test_load = async_test("Test evaluation order of modules");

    window.addEventListener("load", ev => log.push("window-load"));

    function unreachable() { log.push("unexpected"); }
    function testDone() {
      test_load.step(() => {
        assert_array_equals(log, [
             "step-4.1-1", "step-4.1-2", "microtask-4.1",
             "script-load", "window-load",
             "step-4.2-1", "step-4.2-2", "microtask-4.2",
            ]);
      });
      test_load.done();
    }
</script>

<script type="module" src="evaluation-order-4.1.mjs"
    onerror="unreachable()" onload="log.push('script-load')">
 </script>
